import categoryApi from '../../api/category.api';

const state={
  data:[],
  cateGoods: []
};

const getters={
  category: (state: any) => {
    return state.data;
  },

  cateGoods: (state: any) => {
    return state.cateGoods;
  },
};

const actions={
  async getCategory({commit}:any,params: any={}){
    params.filter='level||$eq||L1';
    params.join='children';
    const data=await categoryApi.getCategory(params);
    commit('setData', data);
  },

  async getCateGoods({commit}:any,id: string){
    const params={
      join:['children','children.goods'],
      filter:`id||$eq||${id}`
    }
    const data=await categoryApi.getCategory(params);
    commit('setCateGoods', data);
  }
};

const mutations={
  setData(state: any, data: any){
    state.data = data;
  },

  setCateGoods(state: any, data: any){
    state.cateGoods = data;
  }
};

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}